<template>
  <el-dialog
    class="view_dialog"
    :visible.sync="selfVisible"
    :close-on-press-escape="false"
    :close-on-click-modal="false"
    append-to-body
    fullscreen
    :show-close="false">
    <template #title>
      <div class="dialog_title">
        <span class="close" @click="onClose">
          <i class="el-icon-back"></i>
          退出预览
        </span>
        <p class="title">提示：当前为预览页面，答案不被记录</p>
      </div>
    </template>
    <template>
      <div class="view_box">
        <div class="view_con">
          <div class="title">{{ viewData.assessmentTitle }}</div>
          <div class="sub_title">
            <div class="desc">考核单位：{{ viewData.createByOrgName }}</div>
            <div class="desc">{{ viewData.assessmentSecondTitle }}</div>
          </div>
          <div class="tips-alert">
            <i class="el-icon-warning-outline"></i>
            您所提交的内容完全保密，不会对外泄露！
          </div>
          <div class="filed">
            <!-- <template v-if="pageNum == 1">
              <p class="filed_title">领导测评表</p>
              <div v-for="(item, index) in viewData.leaders" :key="item.id" class="user_li">
                <div class="li_num">
                  <span>*</span>
                  {{ index + 1 }}
                </div>
                <div class="li_con">
                  <div class="name">{{ item.userName }}</div>
                  <el-radio-group v-model="item.assessmentResult" class="radio_box">
                    <el-radio :label="1">好</el-radio>
                    <el-radio :label="2">较好</el-radio>
                    <el-radio :label="3">一般</el-radio>
                    <el-radio :label="4">较差</el-radio>
                  </el-radio-group>
                </div>
              </div>
            </template> -->
            <template v-if="pageNum == 2">
              <p class="filed_title">
                <!-- 非领导成员测评表 -->
              </p>
              <div v-for="(item, index) in viewData.noLeaders" :key="item.id" class="user_li">
                <div class="li_num">
                  <span>*</span>
                  {{ index + 1 }}
                </div>
                <div class="li_con">
                  <div class="name">{{ item.userName }}</div>
                  <el-radio-group v-model="item.assessmentResult" class="radio_box">
                    <el-radio :label="1">好</el-radio>
                    <el-radio :label="2">较好</el-radio>
                    <el-radio :label="3">一般</el-radio>
                    <el-radio :label="4">较差</el-radio>
                  </el-radio-group>
                </div>
              </div>
            </template>
            <!-- <template v-if="pageNum == 3">
              <p class="filed_title">非公务员成员测评表</p>
              <div v-for="(item, index) in viewData.nonCivil" :key="item.id" class="user_li">
                <div class="li_num">
                  <span>*</span>
                  {{ index + 1 }}
                </div>
                <div class="li_con">
                  <div class="name">{{ item.userName }}</div>
                  <el-radio-group v-model="item.assessmentResult" class="radio_box">
                    <el-radio :label="1">好</el-radio>
                    <el-radio :label="2">较好</el-radio>
                    <el-radio :label="3">一般</el-radio>
                    <el-radio :label="4">较差</el-radio>
                  </el-radio-group>
                </div>
              </div>
            </template> -->
            <div class="commit">
              <el-button round type="primary" color="#1989fa" v-if="showpageNum > 1" @click="onBack" plain>
                上一页
              </el-button>
              <el-button
                round
                type="primary"
                color="#1989fa"
                v-if="showpageNum < allpageNum"
                @click="onNextBefore(pageNum)">
                下一页
              </el-button>
              <el-button
                round
                type="primary"
                @click="onNextBefore(pageNum)"
                color="#1989fa"
                v-if="showpageNum == allpageNum">
                提交
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { getAssessmentDetail } from '@apis/mzEvaluation.js'
// import XnDialog from '@com/xnDialog.vue'
export default {
  name: 'EvaluationView',
  components: {},
  data() {
    return {
      viewData: {},
      selfVisible: false,
      id: this.$route.query.id || '',
      pageNum: 1, // 页面实际编码
      allpageNum: 0, // 总页面编码
      showpageNum: 1, // 当前页面编码
    }
  },
  watch: {
    '$route.query': {
      handler(obj) {
        if (obj && obj.id) {
          this.id = obj.id
        }
      },
    },
    visible(bool) {
      this.selfVisible = bool
    },
  },
  methods: {
    show() {
      this.initdata()
      this.selfVisible = true
    },
    onClose() {
      this.selfVisible = false
      this.viewData = {}
      this.pageNum = 1
      this.allpageNum = 0
      this.$emit('update:visible', false)
    },
    /* 初始化数据 */
    initdata() {
      getAssessmentDetail({ id: this.id }).then(res => {
        const data = res.data
        this.viewData = { ...data }
        if (data.leaders && data.leaders.length !== 0) {
          this.allpageNum += 1
        }
        if (data.noLeaders && data.noLeaders.length !== 0) {
          this.allpageNum += 1
        }
        if (data.nonCivil && data.nonCivil.length !== 0) {
          this.allpageNum += 1
        }
        if (data.leaders && data.leaders.length !== 0) {
          this.pageNum = 1
        } else if (data.noLeaders && data.noLeaders.length !== 0) {
          this.pageNum = 2
        } else if (data.nonCivil && data.nonCivil.length !== 0) {
          this.pageNum = 3
        }
      })
    },
    onNextBefore(step) {
      if (this.showpageNum !== this.allpageNum) {
        this.showpageNum = this.showpageNum += 1
        this.pageNum = this.pageNum += 1
      }
    },
    onBack() {
      this.pageNum = this.pageNum -= 1
      this.showpageNum = this.showpageNum -= 1
    },
  },
}
</script>

<style lang="scss" scoped>
.view_dialog {
  font-size: 18px;
  /deep/.el-dialog {
    background: #f2f2f2;
  }
  /deep/.el-dialog__header {
    background: #0060c4;
    color: #fff;
    padding-top: 10px;
    .dialog_title {
      display: flex;
      align-items: center;
      position: relative;
      .close {
        cursor: pointer;
        font-size: 16px;
      }
      .title {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        color: #fff;
        font-size: 18px;
        text-align: center;
      }
    }
  }
  /deep/.el-dialog__body {
    padding: 20px;
    height: calc(100% - 45px);
    .view_box {
      height: 100%;
      margin: 0 auto;
      box-sizing: border-box;
      width: 414px;
      min-width: 414px;
      background: #fff;
      border-radius: 12px;
      box-shadow: #ebedf0 0 4px 12px;
      padding: 25px 0;
      overflow: hidden;
      .view_con {
        padding: 0 15px;
        overflow-x: hidden;
        overflow-y: auto;
        height: 100%;
        .title {
          font-size: 18px;
          color: #333333;
          margin: 15px 0;
          text-align: center;
        }
        .sub_title {
          display: flex;
          justify-content: space-between;
          .desc {
            font-size: 14px;
            margin-bottom: 15px;
          }
        }
        .tips-alert {
          font-size: 14px;
          display: flex;
          align-items: center;
          padding: 9px 15px;
          word-wrap: break-word;
          border-radius: 2px;
          // background-color: #FDF6EC;
          // border: 1px solid #E6A23C;
          // color: #E6A23C;
          background-color: #f2f2f2;
          color: #999;
          i {
            margin-right: 10px;
          }
        }
        .filed_title {
          text-align: center;
          font-size: 16px;
          color: #333;
          font-weight: 600;
          margin: 15px 0;
        }
        .user_li {
          border: solid 1px #eee;
          display: flex;
          align-items: center;
          padding: 10px;
          color: #333;
          &:not(:last-of-type) {
            margin-bottom: 16px;
          }
          .li_num {
            font-size: 14px;
            // text-align: center;
            // margin-right: 10px;
            text-align: left;
            width: 45px;
            span {
              color: rgb(214, 8, 8);
            }
          }
          .li_con {
            flex: 1;
            display: flex;
            align-items: center;
            .name {
              flex: 0.2;
              font-weight: 600;
              font-size: 14px;
              color: #333;
            }
            .radio_box {
              flex: 0.9;
              display: flex;
              justify-content: space-around;
            }
          }
        }
      }
    }

    .commit {
      margin: 80px 0 80px;
      display: flex;
      justify-content: space-around;
      .el-button {
        width: 180px;
      }
    }
  }
}
</style>
